/**
 * Project Name:template-web
 * File Name   :BaseAPIControl.java
 * Package Name:org.cn.template.component.web.control
 * Date:2015年9月27日下午4:36:15
 * Copyright (c) 2015, http://my.oschina.net/httpssl All Rights Reserved.
 *
*/

package org.cn.template.component.web.control;

import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.google.common.collect.Maps;

/**
 * ClassName:BaseAPIControl <br/>
 * Function :TODO ADD FUNCTION. <br/>
 * Reason :TODO ADD REASON. <br/>
 * Date :2015年9月27日 下午4:36:15 <br/>
 * 
 * @author :http://my.oschina.net/httpssl
 * @email :491835898@QQ.COM
 * @since :JDK 1.7
 * @see
 */
public abstract class BaseAPIControl
{
	protected Logger logger = LoggerFactory.getLogger(this.getClass());
	
	/*
	 * 缓存
	 */
	protected static TreeMap<String, Object> dataCache = Maps.newTreeMap();
	/*
	 * 统计100个URL的调用频次
	 */
	protected static ConcurrentHashMap<String, Long> cacheTimer = new ConcurrentHashMap<String, Long>(100);
	
	public ModelAndView redirectView(String redirectUrl) {
		return new ModelAndView(new RedirectView(redirectUrl));
	}

	public ModelAndView toView(String viewPath, Map<String, Object> map) {
		return new ModelAndView(viewPath, map);
	}

	protected ModelAndView apiResult(HttpServletRequest req, Object obj) {
		String api = "api";
		ModelAndView apiView = new ModelAndView(api);
		apiView.addObject(api, obj);
		return apiView;
	}

}
